package com.zhiyou10.crowdfunding.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou10.crowdfunding.service.IUserService;
import com.zhiyou10.crowdfunding.vo.User;
import com.zhiyou10.crowdfunding.vo.mapper.UserMapper;

@Service
public class UserServiceImpl implements IUserService {
	@Autowired
	private UserMapper Mapper;

	@Override
	public boolean add(User vo) throws Exception {
		// TODO Auto-generated method stub
		return this.Mapper.doCreate(vo);
	}

	@Override
	public boolean edit(User vo) throws Exception {
		// TODO Auto-generated method stub
		return this.Mapper.doUpdate(vo);
	}

	@Override
	public User login(String email, String password) throws Exception {
		Map<String, String> map = new HashMap<>();
		map.put("email", email);
		map.put("password", password);
		if (email.contains("@")) {
			User findAdmin = this.Mapper.findAdmin(map);
			return findAdmin;
		}
		// User findAdmin = this.Mapper.findAdmin(map);
		return null;
	}

	@Override
	public User loginPhone(String phone, String password) throws Exception {
		Map<String, String> map = new HashMap<>();
		map.put("phone", phone);
		map.put("password", password);

		User findAdmin = this.Mapper.findAdminPhone(map);
		return findAdmin;
	}

	@Override
	public User get(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return this.Mapper.findById(id);
	}

	@Override
	public boolean editCode(String Code) throws Exception {
		// TODO Auto-generated method stub
		return this.Mapper.doUpdateCode(Code);
	}

}
